package bartenderqueue;

import drinkkiosk.drinks.SpecialDrink;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

/**DrinkButton displays a Drink in the DrinkQueue. The Drink ingredients are
 * listed inside the button. When the Bartender prepares the Drink they touch
 * the DrinkButton and the background color changes. When the Wait Staff picks
 * up the Drink they touch the button and the next Drink in the DrinkQueue replaces
 * the text in the DrinkButton. If no more Drinks are queued the background color
 * changes to black.
 * @author Charles Ritchea
 */
public class DrinkButton extends JButton implements ActionListener{
	/** The Drink object to be displayed in the button */
	private SpecialDrink drink;
	/** The text formed from the Drink ingredients, and displayed on the button */
	private String buttonText;
	/**DrinkButton() initially clears the button text and sets the background
	 * color to black. The Look and Feel is removed giving the button the 
	 * appearance of a solid square. Finally the ActionListener is attached
	 */
        private boolean buttonInUse;

        /**
         * 
         * @param buttonInUse
         */
        public void setButtonInUse(boolean buttonInUse) {
        this.buttonInUse = buttonInUse;
    }

        /**
         * 
         * @return
         */
        public boolean isButtonInUse() {
        return buttonInUse;
    }
        /**
         * 
         */
        public DrinkButton(){
		drink = new SpecialDrink("","","Empty","Empty","Empty","Empty","Empty","Empty");
		drink.setTableNumber("000");
		setContentAreaFilled(false);
                setButtonInUse(false);

		setBackground(Color.BLACK);
		setOpaque(true);
		addActionListener(this);
	}

        /**
         * 
         * @return
         */
        public SpecialDrink getDrink() {
        return drink;
    }
        
     
        
        /**
         * 
         * @param drink
         */
        public synchronized void setFormattedText(SpecialDrink drink){
		buttonText = "<html>"+"<h1>"+drink.getName()+"</h1><br>"+drink.getLiquor()+"<br>"+drink.getLiqueur()+"<br>"+
			drink.getNonalcoholic()+"<br>"+drink.getGarnish()+"<br>"+
			drink.getBarware()+"<br>"+drink.getTemperature()+"<br><h2>"+
			drink.getTableNumber()+"</h2></html>";
		this.setText(buttonText);
	}
	/**The sequence of events that occurs when the DrinkButton is touched.
	 * Initially the button is black. If a Drink enters the DrinkQueue, the
	 * button turns pink. If the button is touched the color changes to green.
	 * If the button is touched again the Drink is removed from the DrinkQueue,
	 * and the color returns to black.
	 * @param e ActionEvent The event of touching the DrinkButton
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		DrinkButton button = (DrinkButton)e.getSource();
		if(getBackground().equals(Color.BLACK)){
		} else if(getBackground().equals(Color.PINK)){
			button.setBackground(Color.GREEN);
		} else if(getBackground().equals(Color.GREEN)) {
			drink = new SpecialDrink("","","Empty","Empty","Empty","Empty","Empty","Empty");
			drink.setTableNumber("000");
			setText("");
			button.setBackground(Color.BLACK);
                        button.setButtonInUse(false);
		}
	}
}
